unit uniEnemyAircraft_Omni;

interface

uses
  uniEnemyAircraft,
  Classes;

type
  { EnemyAircraft_Omni }

  EnemyAircraft_Omni = class(EnemyAircraft)
  public
    constructor Create(et: EnemyType; p: array of Single; randFact: Single = 1.0);
    destructor Destroy; override;

    procedure update;override;
    procedure init; overload; override;
    procedure init(p: array of Single; randFact: Single = 1.0); overload;override;
    procedure move;override;
  end;


implementation

uses
  uniConfig,
  uniGlobal;

{ EnemyAircraft_Omni }

constructor EnemyAircraft_Omni.Create(et: EnemyType; p: array of Single; randFact: Single);
begin
  inherited Create(et, p, randFact);
  init(p, randFact);
end;

destructor EnemyAircraft_Omni.Destroy;
begin
  inherited;
end;

procedure EnemyAircraft_Omni.init;
begin
  inherited init;
end;

procedure EnemyAircraft_Omni.init(p: array of Single; randFact: Single);
var
  frand: Single;
begin
  inherited init(p, randFact);
  frand := frand * randFact;

  damage := -45.0;
  baseDamage := damage;
  size[0] := 0.7;
  size[1] := 0.7;
  collisionMove := 0.7;
  vel[1] := -0.071 - frand * 0.04;
end;

procedure EnemyAircraft_Omni.move;
var
  _config: Config;
  hpos: PSingle;
  diff: array[0..1] of Single;
begin
  _config := uniConfig.instance;

  if Boolean(target) then
    hpos := target.getPos
  else
    hpos := @pos;
  //float	diff[2] := { hpos[0]-pos[0], hpos[1]-pos[1] };
  diff[0] := hpos^ - pos[0]; Inc(hpos);
  diff[1] := hpos^ - pos[1];
  lastMoveX := (0.9 * lastMoveX) + (0.1 * (0.01 * diff[0]));
  pos[0] := pos[0] + uniGlobal.speedAdj * (randMoveX * lastMoveX);
  pos[1] := pos[1] + (uniGlobal.speedAdj * (vel[1] * uniGlobal.gameSkill));

  if (pos[0] < -_config.screenBoundX) then pos[0] := -_config.screenBoundX;
  if (pos[0] > _config.screenBoundX) then pos[0] := _config.screenBoundX;
end;

procedure EnemyAircraft_Omni.update;
var
  _config: Config;
  v, p: array[0..2] of Single;
  hpos: PSingle;
  a, b, dist, ammoSpeed, s: Single;
  omniSwap: integer;
begin
  _config := uniConfig.instance;
  v[0] := 0.0;
  v[1] := -0.2;
  v[2] := 0.0;

  hpos := uniGlobal._hero.getPos;
  a := hpos^ - pos[0]; Inc(hpos);
  b := hpos^ - pos[1];
  ammoSpeed := 0.35 * uniGlobal.speedAdj;

  omniSwap := 100;
  //-- update age
  Inc(age);
  Dec(shootInterval);

  pos[0] := pos[0] + secondaryMove[0] * uniGlobal.speedAdj;
  pos[1] := pos[1] + secondaryMove[1] * uniGlobal.speedAdj;
  s := (1.0 - uniGlobal.speedAdj) + (uniGlobal.speedAdj * 0.7);
  secondaryMove[0] := secondaryMove[0] * s;
  secondaryMove[1] := secondaryMove[1] * s;
  move;

  p[0] := pos[0];
  p[1] := pos[1];
  p[2] := pos[2];

  shootSwap := shootSwap mod omniSwap;
  if (shootSwap < 18) then
  begin
    if (not Boolean(shootSwap mod 6)) then
    begin
      //ammoSpeed := 0.22;
      ammoSpeed := 0.3 * uniGlobal.gameSkill * uniGlobal.speedAdj;
      dist := Abs(a) + Abs(b);
      //dist := sqrt(a*a+b*b);
      v[0] := a / dist;
      v[1] := b / dist;
      shootVec[0] := ammoSpeed * v[0];
      shootVec[1] := ammoSpeed * v[1];
    end;
    uniGlobal._enemyAmmo.addAmmo(1, p, shootVec);
  end;
  if (pos[1] < _config.screenBoundY) then Inc(shootSwap);

end;

end.

